import axios from 'axios'
import Vue from 'vue'
//引入图片预览组件ImagePreview
import { ImagePreview, Toast } from "vant";
Vue.use(ImagePreview).use(Toast);
const http = axios.create({
    baseURL: `https://m.maizuo.com`,
    headers: {
        "X-Client-Info":
            '{"a":"3000","ch":"1002","v":"5.0.4","e":"16308909071367637846130689","bc":"440100"}'
    }
})


// axios 拦截器
// axios.interceptors.request()//请求时拦截
// axios.interceptors.response()//响应时拦截
http.interceptors.request.use(function (config) {
    //设置加载提示
    Toast.loading({
        message: '加载中...',//提示信息
        forbidClick: true,//允许背景点击
        overlay: true,//显示遮罩
        loadingType: "spinner", //加载图标类型，默认circular
        duration: 0 //展示时长(ms)，值为 0 时，toast 不会消失
    });
    return config;
}, function (error) {
    return Promise.reject(error);
});

http.interceptors.response.use(function (response) {
    //请求响应后关闭提示
    Toast.clear()
    return response;
}, function (error) {
    return Promise.reject(error);
});

export default http